<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2018/7/27
  Time: 10:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>退库新增</title>

<script type="text/javascript" src="table.js"></script>
</head>

<body>
<form  action="" class="form-horizontal" role="form" id="myForm" >
    <div class="modal fade bs-example-modal-lg" id="myModal"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" aria-hidden="true" data-backdrop="static">
        <!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
        <div class="modal-dialog modal-lg">
            <!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
            <div class="modal-content">
                <!--  显示模态框白色背景，所有内容都写在这个div里面  -->

                <div class="btn-info modal-header">
                    <!--  模态框标题  -->
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <!--  关闭按钮  -->
                    <h4>退货单添加</h4>
                    <!--  标题内容  -->
                </div>

                <div class="modal-body">
                    <!--  模态框内容，我在此处添加一个表单 -->

                    <div class="form-group">
                        <label  class="col-sm-2 control-label">退货单号</label>
                        <div class="col-sm-9">
                            <input type='text' class="form-control" name="premark1">
                        </div>
                    </div>


                    <div class="form-group">
                        <label  class="col-sm-2 control-label">经办人</label>
                        <div class="col-sm-9">
                            <select class="js-data-example-ajax form-control" name="pman">
                                <option value="1">广东</option>
                                <option value="2">广西</option>
                                <option value="2">广西2</option>
                                <option value="2">广西3</option>
                                <option value="2">广西4</option>
                                <option value="2">广西5</option>
                                <option value="2">广西6</option>
                                <option value="2">广西7</option>
                                <option value="2">广西8</option>
                                <option value="2">广西9</option>
                                <option value="2">广西10</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">退货单位</label>
                        <div class="col-sm-9">
                            
                            <select class="js-data-example-ajax form-control" name="company">
                                <option value="1">一般出库</option>
                                <option value="2">借还出库</option>
                            </select>
                            
                        </div>
                    </div>
                    
                    
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">退库时间</label>
                        <div class="col-sm-9">
                            <div class='input-group date' id='datetimepicker2' >
                                <input type='text' class="form-control" name="time"/>
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div>
                    </div>  
                    
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">退库货物</label>
                        <div class="col-sm-9">
                            
                            <input type='text' class="form-control" id = "goods">
                            
                            <input type="hidden" id="condes" name="condes">                           
                        </div>
                    </div> 
                </div>

                <div class="modal-footer">
                    <!--  模态框底部样式，一般是提交或者确定按钮 -->
                    <button type="button" class="btn btn-info" id="submit">确定</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>

            </div>
        </div>
    </div> 
    
    
    
    <!-- 模态框（Modal） -->
	  <div class="modal fade bs-example-modal-lg" id="goodsModal"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" aria-hidden="true" data-backdrop="static">
	    <div class="modal-dialog modal-lg">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h4 class="modal-title" id="myModalLabel">库存信息</h4>
	            </div>
	            
				<div id="list_op" class="btn-group">
		        
		        </div>
				
	            
	            <div class="modal-body">
	            
	            
	            
	            	<table id="table"></table>
	            </div>
	            <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	                <button type="button" id="save" class="btn btn-primary">提交</button>
	            </div>
	        </div>
	    </div>
	</div>
    
    
    
    
</form>

<script>

var condes = [];

function tableData() {
	
	$("#table").bootstrapTable({
	      method: "post",
	      url: "stock/selectAll.do",
	      height: 300, 
	      toolbar: '#list_op', 
	      method: 'get',                      //请求方式（*）
          striped: true,                      //是否显示行间隔色
          cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
          pagination: false,                   //是否显示分页（*）
          sortable: false,                     //是否启用排序
          sortOrder: "asc",                   //排序方式
          sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
          pageNumber:1,                       //初始化加载第一页，默认第一页
          pageSize: 10,                       //每页的记录行数（*）
          pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
          strictSearch: true,
          minimumCountColumns: 2,             //最少允许的列数
          clickToSelect: true,                //是否启用点击选中行
          uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
          search:true,   //是否启用搜索框
          showRefresh : true, // 是否显示刷新按钮
	      onLoadSuccess: function(){  //加载成功时执行
	            console.info("加载成功");
	      },
	      onLoadError: function(){  //加载失败时执行
	            console.info("加载数据失败");
	      },
	      columns: [{
            checkbox: true
        }, {
            field: 'componentId',
            title: '条形码'
        },  {
            field: 'otype',
            title: '型号',
            
        }, {
            field: 'pame',
            title: '规格',
            
        },{
            field: 'odate',
            title: '种类',
        }, {
            field: 'man',
            title: '单位'
        }, {
            field: 'man',
            title: '品牌'
        }, {
            field: 'man',
            title: '单价'
        }, {
            field: 'man',
            title: '入库时间'
        }]
	}); 
}


    $(function () {
    	
    	 //多选
        $("#sel_menu2").select2({
        	 language: "zh-CN", //设置 提示语言
	       	 width: "100%", //设置下拉框的宽度
	         placeholder: "请选择",
	         tags: true,
	         maximumSelectionLength: 3,  //设置最多可以选择多少项
             allowClear: true,//允许清空			  
        	 ajax: {
        		url: '/jgwork/param_select',
        		type:'GET',
        		dataType: 'json',
        		data: function(){ 
        			
        			return {'projectId':$('#projectSel').val()}
        		},
        		processResults: function (data) {
        			 return {
        				        results: data.result
        				 };
        		 	}
        		}
        });
    	 
    	 /**
    	  * 查询库存
    	  */
    	 $('#goods').mousedown(function() {
    		 
    		 $("#goodsModal").modal('show'); 
    		 
    		 tableData();
    		 
    	 });
    	 
    	 
    	 /**
    	  * 将查询结果带回
    	  */
    	 $('#save').click(function() {
    		 
    		 
    		var row = $("#table").bootstrapTable('getSelections');
    		 
		    for (var i = 0; i < row.length; i++) {
				
		    	condes.push(row[i].componentId);
			}
		    
		  
		    
		    $("#goodsModal").modal('hide'); 
		    
		    $('#condes').val(condes);
    	 });
    	 
    	 
    	 
    	
    	toastr.options.positionClass = 'toast-top-center';

        $('#datetimepicker2').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss',
            locale: moment.locale('zh-cn')
        });
        
        $('#submit').click(function() {
        	
        	$.ajax({
        		type:"POST",
        		url:'partReturn/insert.do',
        		data: $('#myForm').serialize(),
        		success:function(data) {
        			
        			if(data.success) {
        				
        				$("#myModal").modal('hide');
        				
        				toastr.success("添加成功!"); 
        				
        				$('#tb_departments').bootstrapTable('refresh');
        				
        			}else {
        				
        			}
        		}
        	});
        });
    });
    
   
</script>

</body>
</html>

